<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/11 20:58:15 $)
// $RCSfile: parser.php,v $ : $Revision: 1.15 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

define("PARSER_SUCCESS", 1);
define("PARSER_FAILURE", 2);

define("LOG_TICKET", "ticket");
define("LOG_REPLY", "reply");
define("LOG_BUG", "bug");

/**
* Parser Module
*/
class parser {

	/**
	* Constructor to register any events, sections
	*/
	function parser() {
		global $_SWIFT, $events, $datastore;

		$events->registerEventModuleSWIFT(MODULE_PARSER, $this);

		// Command Line Interface
		$events->registerEvent(EVENT_CALLBACK, MODULE_PARSER, "cliparser");

		// Admin Area Nav Bar
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "manageemailqueues");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "insertemailqueue");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "parserlog");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "managebreaklines");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "emailbans");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "catchallrules");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "editcatchallrule");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "editemailban");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "editemailqueue");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "viewparserlog");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "managerules");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "insertparserrule");
		$events->registerEvent(EVENT_ADMIN, MODULE_PARSER, "editparserrule");

		// Cron
		$events->registerEvent(EVENT_CRON, MODULE_PARSER, "cron");
		$events->registerEvent(EVENT_CRON, MODULE_PARSER, "cleanup");

		$eventaction = $events->eventdata["eventaction"];
		$datastore->cache("departmentcache");
		$datastore->cache("queuecache");
		$datastore->cache("statuscache");
		$datastore->cache("prioritycache");
		$datastore->cache("departmentcache");
		$datastore->cache("breaklinecache");
		$datastore->cache("parsercatchallcache");
		$datastore->cache("slaplancache");
		$datastore->cache("slaschedulecache");
		$datastore->cache("staffassigncache");
		$datastore->cache("groupassigncache");
		$datastore->cache("staffcache");
		$datastore->cache("ticketcountcache");
		$datastore->cache("parserbanscache");
		$datastore->cache("attachmenttypescache");

	}

	/**
	* Destructor, called to unregister any events etc
	*/
	function _parser() {
	}

	/*
	* Call back function
	*/
	function _eventcallback($eventtype, $eventaction)
	{
		global $_SWIFT, $interface, $template, $departments, $staffauth, $module, $grid, $xml, $staff, $settings, $dbCore, $events, $session, $loginshare, $cookie, $errormessage, $infomessage, $permissions, $mimelist;

		if ($eventtype == EVENT_CALLBACK && $eventaction == "cliparser")
		{
			require_once ("./modules/parser/cli_parser.php");
			return true;
		} else if ($eventtype == EVENT_CRON && $eventaction == "cron") {
			if (defined("SWIFTCUSTOMPATH"))
			{
				require_once (SWIFTCUSTOMPATH."/modules/parser/cron_parser.php");
			} else {
				require_once ("./modules/parser/cron_parser.php");
			}
			return true;
		} else if ($eventtype == EVENT_CRON && $eventaction == "cleanup") {
			require_once ("./modules/parser/cron_cleanup.php");
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "manageemailqueues" || $eventaction == "insertemailqueue" || $eventaction == "parserlog" || $eventaction == "managebreaklines" || $eventaction == "editemailqueue" || $eventaction == "viewparserlog")) {
			require_once ("./modules/parser/admin_parser.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managerules" || $eventaction == "insertparserrule" || $eventaction == "editparserrule")) {
			require_once ("./modules/parser/admin_parserrules.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "catchallrules" || $eventaction == "emailbans" || $eventaction == "editcatchallrule" || $eventaction == "editemailban")) {
			require_once ("./modules/parser/admin_misc.php");
			return true;
		}
		

		return false;
	}
}
?>